<%--@elvariable id="APP_PATH" type=""--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${APP_PATH}/css/font-awesome.min.css">
    <link rel="stylesheet" href="${APP_PATH}/css/main.css">
    <link rel="stylesheet" href="${APP_PATH}/ztree/zTreeStyle.css">
    <style>
        .tree li {
            list-style-type: none;
            cursor: pointer;
        }

        table tbody tr:nth-child(odd) {
            background: #F4F4F4;
        }

        table tbody td:nth-child(even) {
            color: #C00;
        }
    </style>
</head>

<body>

<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <div><a class="navbar-brand" style="font-size:32px;" href="#">众筹平台 - 用户维护</a></div>
        </div>
        <%@include file="../common/top.jsp"%>
    </div>
</nav>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <div class="tree">
                <%@include file="../common/menu.jsp"%>
            </div>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
                </div>
                <div class="panel-body">
                    <button onclick="doAssign()" class="btn btn-success">分配许可</button>
                    <ul id="permissionTree" class="ztree"></ul>

                </div>
            </div>
        </div>
    </div>
</div>
</div>

<script src="${APP_PATH}/jquery/jquery-2.1.1.min.js"></script>
<script src="${APP_PATH}/bootstrap/js/bootstrap.min.js"></script>
<script src="${APP_PATH}/script/docs.min.js"></script>
<script src="${APP_PATH}/layer/layer.js"></script>
<script src="${APP_PATH}/ztree/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript">
    $(function () {
        $(".list-group-item").click(function () {
            if ($(this).find("ul")) {
                $(this).toggleClass("tree-closed");
                if ($(this).hasClass("tree-closed")) {
                    $("ul", this).hide("fast");
                } else {
                    $("ul", this).show("fast");
                }
            }
        });
        var setting = {
            async: {
                enable: true,
                url: "${APP_PATH}/permission/loadCurrentData?roleid=${param.id}",
                autoParam: ["id", "name=n", "level=lv"]
            },
            check : {
                enable : true
            }
        };
        $.fn.zTree.init($("#permissionTree"), setting);
    });
    $("tbody .btn-success").click(function () {
        window.location.href = "assignRole.html";
    });
    $("tbody .btn-primary").click(function () {
        window.location.href = "edit.html";
    });
    function doAssign() {
        /*
        * 1,判断是否选择了权限
        * 2，ajax提交后台
        * 3，怎么获得json的data给后台
        * */
        var treeObj = $.fn.zTree.getZTreeObj("permissionTree");
        var nodes = treeObj.getCheckedNodes(true); // 获取被选中的节点
        if (nodes.length == 0) {
            layer.msg("选择的权限许可为空", {time: 2000, icon: 5, shift: 6}, function () {

            });
        }else{
            var datas="roleid=${param.id}";
            $.each(nodes,function (i,node) {
                datas+="&permissionids="+node.id;
            });
            $.ajax({
                type: "POST",
                url: "${APP_PATH}/role/doAssign",
                data: datas,
                success:function (result) {
                    if (result.success) {
                        layer.msg("分配权限许可成功", {time: 2000, icon: 6}, function () {

                        });
                    }else{
                        layer.msg("分配权限许可失败", {time: 2000, icon: 5, shift: 6}, function () {

                        });
                    }
                }
            });
        }
    }
</script>
</body>
</html>

